import { createRouter, createWebHashHistory } from 'vue-router'
import { getLocal } from '@/utils/cookie'
// import Layout from '@/views/index'
const router = createRouter({
  history: createWebHashHistory(), // hash模式：createWebHashHistory,history模式：createWebHistory
  routes: [
    {
      path: '/',
      component: () => import('@/views/index'),
      redirect: '/home',
      children: [
        {
          path: 'home',
          name: 'home',
          component: () => import('@/views/home/index'),
          meta: {
            title: '智慧养老服务',
            content: {
              keywords: '',
              description: '',
            },
          },
        },
      ],
    },
    {
      path: '/productCenter',
      name: 'productCenter',
      component: () => import('@/views/productCenter/index'),
      meta: {
        title: '产品中心',
      },
    },
    {
      path: '/solution',
      name: 'solution',
      component: () => import('@/views/index'),
      children: [
        {
          path: '',
          name: '',
          component: () => import('@/views/solution/index'),
          meta: {
            title: '解决方案',
          },
        },
        {
          path: 'familySolution',
          name: 'familySolution',
          component: () => import('@/views/solution/childComps/familySolution'),
          meta: {
            title: '家庭养老床位解决方案',
          },
        },
        {
          path: 'kanhuSolution',
          name: 'kanhuSolution',
          component: () => import('@/views/solution/childComps/kanhuSolution'),
          meta: {
            title: '智慧看护解决方案',
          },
        },
        {
          path: 'yiyangSolution',
          name: 'yiyangSolution',
          component: () => import('@/views/solution/childComps/yiyangSolution'),
          meta: {
            title: '智慧环卫解决方案',
          },
        },
        {
          path: 'huanweiSolution',
          name: 'huanweiSolution',
          component: () => import('@/views/solution/childComps/huanweiSolution'),
          meta: {
            title: '智慧环卫解决方案',
          },
        },
        {
          path: 'fangyiSolution',
          name: 'fangyiSolution',
          component: () => import('@/views/solution/childComps/fangyiSolution'),
          meta: {
            title: '智慧环卫解决方案',
          },
        },
      ],
    },
    {
      path: '/aboutUs',
      name: 'aboutUs',
      component: () => import('@/views/index'),
      meta: {
        title: '关于我们',
      },
      children: [
        {
          path: '',
          name: '',
          component: () => import('@/views/aboutUs/index'),
          meta: {
            title: '关于我们',
          },
        },
        {
          path: 'ryzizhi',
          name: 'ryzizhi',
          component: () => import('@/views/aboutUs/childComps/ryzizhi'),
          meta: {
            title: '荣誉资质',
          },
        },
        {
          path: 'contactUs',
          name: 'contactUs',
          component: () => import('@/views/aboutUs/childComps/contactUs'),
          meta: {
            title: '联系我们',
          },
        },
      ],
    },
    {
      path: '/caseExample',
      name: 'caseExample',
      component: () => import('@/views/caseExample/index'),
      meta: {
        title: '案例中心',
      },
    },
    {
      path: '/techServe',
      name: 'techServe',
      component: () => import('@/views/techServe/index'),
      meta: {
        title: '服务与支持',
      },
    },
    {
      path: '/:mathAll(.*)',
      name: 'notfound',
      component: () => import('@/views/404/404'),
    },
    {
      path: '/login',
      name: 'login',
      component: () => import('@/views/login/login'),
      meta: {
        title: '登录',
      },
    },
    {
      path: '/register',
      name: 'register',
      component: () => import('@/views/login/register'),
      meta: {
        title: '注册',
      },
    },
  ],
})

export default router

router.beforeEach((to, from, next) => {
  if (to.meta && to.meta.title) {
    document.title = to.meta.title
  }
  next()
})
